// VectorsOperation.cpp
// Implementation of vector's dot product, cross product, normalize, get magnitude method
// A vector can be treated as a 1(row) by 0(column) matrix
// A point an be treated as a 3d vector: <x,y,z,0>


#include "VectorsLib.h"

using namespace std;

namespace Vectors
{
	int n = 4;
	float magnitude;
	float scalar;
	float vector[4];


	////////////////////////////////
	/* Vector Constructor
	*/
	////////////////////////////////
	MyVectors::MyVectors(){}
	MyVectors::MyVectors(float x, float y, float z)
	{
		vector[0] = x;
		vector[1] = y;
		vector[2] = z;
		vector[3] = 0;
	}
	MyVectors::MyVectors(float *v){}



	////////////////////////////////
	/* Read vectors from the input
	*/
	////////////////////////////////
	float (*MyVectors::ReadVector())
	{
		cout<<"Please enter the elements of the vector: "<<endl;
		for(int i = 0; i < n; i++)
			cin>> vector[i];
		cin.sync(); 

		return vector;
	}


	////////////////////////////////
	/* Calculate the dot product between 2 vectors(vector1 and vector 2)
	*/
	////////////////////////////////
	float MyVectors::DotProduct(float *vector1, float *vector2)
	{
		for(int i = 0; i < n; i++){
			float v = vector1[i] * vector2[i];
			scalar = scalar + v;
		}
		return scalar;
	}


	////////////////////////////////
	/* Calculate the cross product between 2 vectors(vector1 and vector2)
	   vector(x,y,z,0)
	*/
	////////////////////////////////
	float (*MyVectors::CrossProduct(float *vector1, float *vector2))
	{
		vector[0] = vector1[1] * vector2[2] - vector1[2] * vector2[1];
		vector[1] = vector1[2] * vector2[0] - vector1[0] * vector2[2];
		vector[2] = vector1[0] * vector2[1] - vector1[1] * vector2[0];
		vector[3] = 0;
		return vector;
	}


	////////////////////////////////
	/* Calculate the magnitude
	   param int n: the number of vector's elements
	*/
	////////////////////////////////
	float MyVectors::GetMagnitude(float *vector1)
	{
		magnitude = sqrt(vector1[0] * vector1[0] + vector1[1] * vector1[1] + vector1[2] * vector1[2] + vector1[3] * vector1[3]);
		return magnitude;
	}


	////////////////////////////////
	/* Normalize the vector: *vector1 to *vector
  	   param int n: the number of vector's elements
	*/
	////////////////////////////////
	float (*MyVectors::NormalizeVector(float *vector1))
	{
		vector[0] = 1 / GetMagnitude(vector1) * vector1[0];
		vector[1] = 1 / GetMagnitude(vector1) * vector1[1];
		vector[2] = 1 / GetMagnitude(vector1) * vector1[2];
		vector[3] = 1 / GetMagnitude(vector1) * vector1[3];

		return vector;
	}


}